package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.SmolSprite;
import com.corona.game.util.TextureCache;
import com.corona.game.util.texture.DynamicTextures;
import com.sun.jna.platform.win32.WinError;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

/* compiled from: PkmnMap.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/MoveWater.class */
public class MoveWater extends Action {
    Vector2 position;
    ArrayList<Integer> repeats;
    Tile tile;
    Pixmap pixmap;
    Pixmap roamingPixmap;
    Texture roamingTexture;
    Pixmap firePixmap1;
    Pixmap firePixmap2;
    Pixmap torchPixmap1;
    Pixmap torchPixmap2;
    Pixmap currPixmap;
    Pixmap currTorchPixmap;
    public static int shoreIndex = 0;
    public static int regiTimer2 = 0;
    public Action.Layer layer = Action.Layer.map_109;
    Sprite[] torchSprites = new Sprite[2];
    int campfireTimer = 0;
    int avatarTimer = 0;
    int waterTimer = 0;
    int regiCaveTimer = 0;
    int shoreTimer = 0;
    int modX = 0;
    public boolean justFlipped = false;
    int regiCaveInterval = 40;
    int timer = 0;
    Vector2 prevPos = new Vector2();
    public HashMap<Tile, String> placeWater = new HashMap<>();
    ArrayList<Vector2> positions = new ArrayList<>();
    Sprite[] campfireSprites = new Sprite[4];

    public MoveWater(Game game) {
        super(new Object[0]);
        resetVars();
        Texture text = TextureCache.get(Gdx.files.internal("tiles/campfire1.png"));
        this.campfireSprites[0] = new Sprite(text, 0, 0, 16, 20);
        this.campfireSprites[1] = new Sprite(text, 16, 0, 16, 20);
        Texture text2 = TextureCache.get(Gdx.files.internal("tiles/torch_sheet1.png"));
        this.torchSprites[0] = new Sprite(text2, 0, 60, 16, 20);
        this.torchSprites[1] = new Sprite(text2, 16, 60, 16, 20);
        TextureData temp = TextureCache.get(Gdx.files.internal("torch_mask1.png")).getTextureData();
        if (!temp.isPrepared()) {
            temp.prepare();
        }
        this.torchPixmap1 = temp.consumePixmap();
        TextureData temp2 = TextureCache.get(Gdx.files.internal("torch_mask2.png")).getTextureData();
        if (!temp2.isPrepared()) {
            temp2.prepare();
        }
        this.torchPixmap2 = temp2.consumePixmap();
        Texture text3 = TextureCache.get(Gdx.files.internal("fire_mask3.png"));
        this.campfireSprites[2] = new Sprite(text3, 0, 0, 160, 144);
        TextureData temp3 = text3.getTextureData();
        if (!temp3.isPrepared()) {
            temp3.prepare();
        }
        this.firePixmap1 = temp3.consumePixmap();
        Texture text4 = TextureCache.get(Gdx.files.internal("fire_mask4.png"));
        this.campfireSprites[3] = new Sprite(text4, 0, 0, 160, 144);
        TextureData temp4 = text4.getTextureData();
        if (!temp4.isPrepared()) {
            temp4.prepare();
        }
        this.firePixmap2 = temp4.consumePixmap();
        this.pixmap = new Pixmap((int) WinError.ERROR_MULTIPLE_FAULT_VIOLATION, 432, Pixmap.Format.RGBA8888);
        this.pixmap.setColor(new Color(0.0f, 0.0f, 0.0f, 0.0f));
        this.roamingPixmap = new Pixmap((int) WinError.ERROR_MULTIPLE_FAULT_VIOLATION, 432, Pixmap.Format.RGBA8888);
        this.roamingPixmap.setColor(new Color(0.0f, 0.0f, 0.0f, 1.0f));
        this.roamingTexture = TextureCache.get(this.roamingPixmap);
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    public void resetVars() {
        this.position = new Vector2(0.0f, 0.0f);
        this.positions.add(new Vector2(0.0f, 0.0f));
        this.positions.add(new Vector2(1.0f, 0.0f));
        this.positions.add(new Vector2(2.0f, 0.0f));
        this.positions.add(new Vector2(3.0f, 0.0f));
        this.positions.add(new Vector2(2.0f, 0.0f));
        this.positions.add(new Vector2(1.0f, 0.0f));
        this.repeats = new ArrayList<>();
        this.repeats.add(19);
        this.repeats.add(19);
        this.repeats.add(19);
        this.repeats.add(19);
        this.repeats.add(19);
        this.repeats.add(19);
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        Pokemon pokemon;
        Sprite newSprite;
        if (!game.player.dontDrawMapDuringBattle) {
            this.roamingPixmap.fill();
            if (this.campfireTimer % 10 == 0) {
                this.pixmap.fill();
                this.prevPos.set(game.player.position.x, game.player.position.y);
            }
            if (!Game.canUseFrameBuffers) {
                this.currPixmap = this.firePixmap2;
                this.currTorchPixmap = this.torchPixmap2;
                if (this.campfireTimer % 20 < 10) {
                    this.currPixmap = this.firePixmap1;
                    this.currTorchPixmap = this.torchPixmap1;
                }
            }
            for (int i = 0; i < game.map.onscreenTiles.size(); i++) {
                Tile tile = game.map.onscreenTiles.get(i);
                if (tile.isWater) {
                    tile.sprite.setRegionX((int) this.position.x);
                    tile.sprite.setRegionWidth((int) tile.sprite.getWidth());
                } else if (tile.name.contains("flower")) {
                    if (this.timer == 0) {
                        tile.sprite.setRegion(0, 0, 16, 16);
                    } else if (this.timer == 26) {
                        tile.sprite.setRegion(16, 0, 16, 16);
                    }
                } else if (tile.isWaterfall) {
                    if (this.campfireTimer % 40 == 0) {
                        tile.sprite.setRegion(tile.sprite.getRegionX() % 48, tile.sprite.getRegionY(), 16, 16);
                    } else if (this.campfireTimer % 40 == 19) {
                        tile.sprite.setRegion((tile.sprite.getRegionX() % 48) + 48, tile.sprite.getRegionY(), 16, 16);
                    }
                } else if (tile.isLava) {
                    if (this.campfireTimer % 20 == 0) {
                        tile.sprite.setRegion((tile.sprite.getRegionX() % 48) + (96 * (this.campfireTimer / 20)), tile.sprite.getRegionY(), 16, 16);
                    } else if (this.campfireTimer % 20 == 3) {
                        tile.sprite.setRegion((tile.sprite.getRegionX() % 48) + 48 + (96 * (this.campfireTimer / 20)), tile.sprite.getRegionY(), 16, 16);
                    }
                }
                if (tile.nameUpper.equals("campfire1")) {
                    if (this.campfireTimer == 0) {
                        SmolSprite newSprite2 = new SmolSprite(this.campfireSprites[0]);
                        newSprite2.setPosition(tile.overSprite.getX(), tile.overSprite.getY());
                        tile.overSprite = newSprite2;
                    } else if (this.campfireTimer == 40) {
                        SmolSprite newSprite3 = new SmolSprite(this.campfireSprites[1]);
                        newSprite3.setPosition(tile.overSprite.getX(), tile.overSprite.getY());
                        tile.overSprite = newSprite3;
                    }
                    if (!Game.canUseFrameBuffers && this.campfireTimer % 10 == 0 && game.mapBatch.getColor().r < 0.5f) {
                        this.pixmap.drawPixmap(this.currPixmap, (int) ((tile.position.x - 80.0f) - (game.player.position.x - 320.0f)), (int) (296.0f - (((tile.position.y + 8.0f) - 72.0f) - (game.player.position.y - 216.0f))));
                    }
                } else if (tile.isTorch) {
                    if (this.campfireTimer < 40) {
                        newSprite = new Sprite(this.torchSprites[0]);
                    } else {
                        newSprite = new Sprite(this.torchSprites[1]);
                    }
                    Color color = game.mapBatch.getColor().cpy();
                    if (game.mapBatch.getColor().r < 0.5f) {
                        game.mapBatch.setColor(0.2f, 0.2f, 0.2f, 1.0f);
                        if (!Game.canUseFrameBuffers && this.campfireTimer % 10 == 0) {
                            this.pixmap.drawPixmap(this.currTorchPixmap, ((int) ((tile.position.x - 80.0f) - (game.player.position.x - 320.0f))) + 40, ((int) (296.0f - (((tile.position.y + 8.0f) - 72.0f) - (game.player.position.y - 216.0f)))) + 36);
                        }
                    }
                    game.mapBatch.draw(newSprite, tile.position.x + ((float) 0), tile.position.y + 4.0f + 2.0f);
                    game.mapBatch.setColor(color);
                } else if (tile.name.equals("cave1_regi3")) {
                    if (game.battle.drawAction != null) {
                        if (regiTimer2 == 0) {
                            tile.sprite.setRegion(160, 0, 32, 32);
                        }
                        this.justFlipped = true;
                    } else {
                        if (this.justFlipped) {
                            this.justFlipped = false;
                            tile.sprite.setPosition(tile.position.x, tile.position.y);
                            tile.sprite.setRegion(128, 0, 32, 32);
                        }
                        if (regiTimer2 == 0) {
                            tile.sprite.setRegion(160, 0, 32, 32);
                        } else if (regiTimer2 == 4) {
                            tile.sprite.setRegion(128, 0, 32, 32);
                        } else if (regiTimer2 == 8) {
                            tile.sprite.setRegion(160, 0, 32, 32);
                        } else if (regiTimer2 == 12) {
                            tile.sprite.setRegion(128, 0, 32, 32);
                        } else if (regiTimer2 == 16) {
                            tile.sprite.setRegion(160, 0, 32, 32);
                        } else if (regiTimer2 == 20) {
                            tile.sprite.setRegion(128, 0, 32, 32);
                        } else if (regiTimer2 == 52) {
                            tile.sprite.setRegion(192, 0, 32, 32);
                        } else if (regiTimer2 == 56) {
                            tile.sprite.setRegion(224, 0, 32, 32);
                        } else if (regiTimer2 == 60) {
                            tile.sprite.setRegion(256, 0, 32, 32);
                        } else if (regiTimer2 == 64) {
                            tile.sprite.setRegion(288, 0, 32, 32);
                        } else if (regiTimer2 == 68) {
                            tile.sprite.setRegion(128, 0, 32, 32);
                        }
                    }
                } else if (tile.nameUpper.contains("revived_")) {
                    String name = tile.nameUpper.split("_")[1];
                    if (!Specie.species.containsKey(name)) {
                        Specie.species.put(name, new Specie(name));
                    }
                    int index = 0;
                    if (this.avatarTimer < 60) {
                        index = 1;
                    }
                    game.mapBatch.draw(Specie.species.get(name).avatarSprites.get(index), tile.position.x + 8.0f, tile.position.y + 8.0f);
                } else if (tile.nameUpper.equals("volcarona")) {
                    if (!Game.canUseFrameBuffers && this.campfireTimer % 10 == 0 && game.mapBatch.getColor().r < 0.5f) {
                        this.pixmap.drawPixmap(this.currPixmap, (int) ((tile.position.x - 80.0f) - (game.player.position.x - 320.0f)), (int) (296.0f - (((tile.position.y + 8.0f) - 72.0f) - (game.player.position.y - 216.0f))));
                    }
                    String name2 = tile.nameUpper;
                    if (!Specie.species.containsKey(name2)) {
                        Specie.species.put(name2, new Specie(name2));
                    }
                    int index2 = 0;
                    if (this.avatarTimer < 60) {
                        index2 = 1;
                    }
                    game.mapBatch.draw(Specie.species.get(name2).avatarSprites.get(index2), tile.position.x, tile.position.y + 4.0f);
                } else if (tile.nameUpper.equals("spiritomb")) {
                    String name3 = tile.nameUpper;
                    if (!Specie.species.containsKey(name3)) {
                        Specie.species.put(name3, new Specie(name3));
                    }
                    int index3 = 0;
                    if (this.avatarTimer < 60) {
                        index3 = 1;
                    }
                    game.mapBatch.draw(Specie.species.get(name3).avatarSprites.get(index3), tile.position.x, tile.position.y + 4.0f);
                } else if (this.waterTimer == 0 && tile.nameUpper.contains("hole") && !tile.nameUpper.contains("water")) {
                    boolean placeWater = false;
                    boolean placeLava = false;
                    for (Vector2 position : new Vector2[]{new Vector2(0.0f, -16.0f), new Vector2(0.0f, 16.0f), new Vector2(-16.0f, 0.0f), new Vector2(16.0f, 0.0f)}) {
                        Tile currTile = game.map.tiles.get(tile.position.cpy().add(position));
                        if (currTile != null) {
                            if (currTile.name.contains("water") || currTile.nameUpper.contains("water")) {
                                placeWater = true;
                            } else if (currTile.name.contains("lava") || currTile.nameUpper.contains("lava")) {
                                placeLava = true;
                            }
                        }
                    }
                    if (placeWater && placeLava) {
                        this.placeWater.put(tile, "soot1");
                    } else if (placeLava) {
                        this.placeWater.put(tile, "lava1");
                    } else if (placeWater) {
                        this.placeWater.put(tile, "water2");
                    }
                } else if (tile.isChimney) {
                    tile.overSprite.setRegion(DynamicTextures.get(tile.nameUpper, this.campfireTimer / 20));
                }
                if (!Game.canUseFrameBuffers && (pokemon = game.map.pokemon.get(tile.position)) != null && pokemon.mapTiles == game.map.tiles && pokemon.hms.contains("FLASH") && game.mapBatch.getColor().r < 0.5f) {
                    this.roamingPixmap.drawPixmap(this.currPixmap, (int) ((pokemon.position.x - 80.0f) - (game.player.position.x - 320.0f)), (int) (296.0f - (((pokemon.position.y + 8.0f) - 72.0f) - (game.player.position.y - 216.0f))));
                }
            }
            if (!Game.canUseFrameBuffers) {
                if (game.mapBatch.getColor().r < 0.5f && game.player.hmPokemon != null && game.player.hmPokemon.currOwSprite != null && game.player.hmPokemon.hms.contains("FLASH")) {
                    Vector2 position2 = game.player.hmPokemon.position;
                    if (!game.player.currFieldMove.equals("")) {
                        position2 = game.player.position;
                    }
                    this.roamingPixmap.drawPixmap(this.currPixmap, (int) ((position2.x - 80.0f) - (game.player.position.x - 320.0f)), (int) (296.0f - (((position2.y + 8.0f) - 72.0f) - (game.player.position.y - 216.0f))));
                }
                if (game.mapBatch.getColor().r < 1.0f) {
                    Color tempColor = game.mapBatch.getColor().cpy();
                    game.mapBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                    int temp1 = game.mapBatch.getBlendSrcFunc();
                    int temp2 = game.mapBatch.getBlendDstFunc();
                    game.mapBatch.setBlendFunction(774, 770);
                    this.roamingPixmap.drawPixmap(this.pixmap, (int) (this.prevPos.x - game.player.position.x), (int) (game.player.position.y - this.prevPos.y));
                    this.roamingTexture.draw(this.roamingPixmap, 0, 0);
                    game.mapBatch.draw(this.roamingTexture, (game.player.position.x + 8.0f) - 320.0f, (game.player.position.y + 8.0f) - 216.0f);
                    if (tempColor.r < 0.5f) {
                        game.mapBatch.draw(this.roamingTexture, (game.player.position.x + 8.0f) - 320.0f, (game.player.position.y + 8.0f) - 216.0f);
                    }
                    if (tempColor.r < 0.1f) {
                        game.mapBatch.draw(this.roamingTexture, (game.player.position.x + 8.0f) - 320.0f, (game.player.position.y + 8.0f) - 216.0f);
                    }
                    game.mapBatch.setBlendFunction(temp1, temp2);
                    game.mapBatch.setColor(tempColor);
                }
            }
            if (this.shoreTimer == 0) {
                shoreIndex = 1;
            } else if (this.shoreTimer == 16) {
                shoreIndex = 2;
            } else if (this.shoreTimer == 32) {
                shoreIndex = 3;
                Vector2 pos = game.player.position.cpy();
                pos.x -= pos.x % 16.0f;
                pos.y -= pos.y % 16.0f;
                Tile currTile2 = game.map.tiles.get(pos);
                if (!(currTile2 == null || (currTile2.shoreOcean == null && currTile2.shoreTidal == null))) {
                    Player player = game.player;
                    Objects.requireNonNull(player);
                    Player player2 = game.player;
                    Objects.requireNonNull(player2);
                    game.insertAction(new Player.WaterSplash(player, true, new Player.WaterSplash(player2, false, null)));
                }
            } else if (this.shoreTimer == 48) {
                shoreIndex = 4;
                Vector2 pos2 = game.player.position.cpy();
                pos2.x -= pos2.x % 16.0f;
                pos2.y -= pos2.y % 16.0f;
                Tile currTile3 = game.map.tiles.get(pos2);
                if (!(currTile3 == null || (currTile3.shoreOcean == null && currTile3.shoreTidal == null))) {
                    Player player3 = game.player;
                    Objects.requireNonNull(player3);
                    Player player4 = game.player;
                    Objects.requireNonNull(player4);
                    game.insertAction(new Player.WaterSplash(player3, true, new Player.WaterSplash(player4, false, null)));
                }
            } else if (this.shoreTimer == 64) {
                shoreIndex = 5;
            } else if (this.shoreTimer == 80) {
                shoreIndex = 6;
            } else if (this.shoreTimer == 96) {
                shoreIndex = 0;
            }
            if (this.shoreTimer < 128) {
                this.shoreTimer++;
            } else {
                this.shoreTimer = 0;
            }
            if (this.campfireTimer < 79) {
                this.campfireTimer++;
            } else {
                this.campfireTimer = 0;
            }
            if (this.avatarTimer < 120) {
                this.avatarTimer++;
            } else {
                this.avatarTimer = 0;
            }
            if (this.waterTimer < 60) {
                this.waterTimer++;
            } else {
                this.waterTimer = 0;
            }
            if (game.battle.drawAction != null && regiTimer2 < 30) {
                regiTimer2++;
            } else if (game.battle.drawAction != null || regiTimer2 >= 160) {
                regiTimer2 = 0;
            } else {
                regiTimer2++;
            }
            if (game.map.currRoute == null || game.battle.drawAction != null || !game.map.currRoute.name.equals("regi_cave1")) {
                game.uiBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
            } else {
                game.uiBatch.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
                game.mapBatch.setColor(new Color(0.6f, 0.6f, 0.6f, 1.0f));
                if (this.regiCaveTimer < this.regiCaveInterval * 1) {
                    game.uiBatch.setColor(new Color(0.7f, 0.7f, 0.8f, 1.0f));
                    game.mapBatch.setColor(new Color(0.5f, 0.5f, 0.8f, 1.0f));
                } else if (this.regiCaveTimer < this.regiCaveInterval * 2) {
                    game.uiBatch.setColor(new Color(0.6f, 0.6f, 0.7f, 1.0f));
                    game.mapBatch.setColor(new Color(0.4f, 0.4f, 0.7f, 1.0f));
                } else if (this.regiCaveTimer < this.regiCaveInterval * 3) {
                    game.uiBatch.setColor(new Color(0.7f, 0.7f, 0.8f, 1.0f));
                    game.mapBatch.setColor(new Color(0.3f, 0.3f, 0.6f, 1.0f));
                } else if (this.regiCaveTimer < this.regiCaveInterval * 4) {
                    game.uiBatch.setColor(new Color(0.6f, 0.6f, 0.7f, 1.0f));
                    game.mapBatch.setColor(new Color(0.2f, 0.2f, 0.5f, 1.0f));
                } else if (this.regiCaveTimer < this.regiCaveInterval * 5) {
                    game.uiBatch.setColor(new Color(0.7f, 0.7f, 0.8f, 1.0f));
                    game.mapBatch.setColor(new Color(0.3f, 0.3f, 0.6f, 1.0f));
                } else {
                    game.uiBatch.setColor(new Color(0.6f, 0.6f, 0.7f, 1.0f));
                    game.mapBatch.setColor(new Color(0.4f, 0.4f, 0.7f, 1.0f));
                }
                if (this.regiCaveTimer < this.regiCaveInterval * 6) {
                    this.regiCaveTimer++;
                } else {
                    this.regiCaveTimer = 0;
                }
            }
            if (!this.placeWater.isEmpty()) {
                for (Tile tile2 : this.placeWater.keySet()) {
                    tile2.name = this.placeWater.get(tile2);
                    tile2.nameUpper = "";
                    tile2.init();
                    game.map.adjustSurroundingTiles(tile2);
                }
                if (game.battle.drawAction == null && game.playerCanMove) {
                    game.insertAction(new PlayMusic("sand1", 0.5f, true, null));
                }
                this.placeWater.clear();
            }
            if (this.repeats.get(0).intValue() > 0) {
                this.repeats.set(0, Integer.valueOf(this.repeats.get(0).intValue() - 1));
            } else {
                this.position = this.positions.remove(0);
                this.repeats.remove(0);
                if (this.positions.isEmpty()) {
                    resetVars();
                }
                DrawMapGrass.tidalSprite.setRegionX((int) this.positions.get(0).x);
                DrawMapGrass.tidalSprite.setRegionWidth((int) DrawMapGrass.tidalSprite.getWidth());
            }
            this.timer++;
            if (this.timer >= 52) {
                this.timer = 0;
            }
        }
    }
}
